package com.etoak.controller;

import com.etoak.common.vo.ResultVO;
import com.etoak.common.vo.TourVO;
import com.etoak.entity.Tour;
import com.etoak.service.TourService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/tour")
public class TourController {

    @Autowired
    TourService tourService;

    @PutMapping("/add")
    public ResultVO addTour(@RequestBody TourVO tour) {
        int i = tourService.addTour(tour);
        if (i != 0) {
            return ResultVO.success(true);
        }
        return ResultVO.error(false);
    }

    @RequestMapping("/query")
    public ResultVO queryTour(@RequestBody TourVO vo){
        List<TourVO> tours = tourService.queryTour(vo);
        return ResultVO.success(tours);
    }

    @PostMapping("/{id}")
    public ResultVO queryById(@PathVariable int id){
        TourVO vo = tourService.queryById(id);
        return ResultVO.success(vo);
    }

}
